# Contributor: Hani Shawa <hani.shawa@ev-box.com>
# Maintainer: Hani Shawa <hani.shawa@ev-box.com>
pkgname=luacov
_rockname=${pkgname#lua-}
pkgver=0.15.0
pkgrel=0
pkgdesc="simple coverage analysis tool for Lua scripts"
url="https://github.com/keplerproject/luacov"
license="MIT"
arch="noarch"
makedepends="luarocks"
options="!check" # Test dependencies not available
source="$_rockname-$pkgver.tar.gz::https://github.com/keplerproject/luacov/archive/v$pkgver.tar.gz
reporter_fix.lua.patch
"

_luaversions="5.1 5.2 5.3 5.4"

for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev luarocks$_v"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

build() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."

		luarocks-$lver \
			LUA_INCDIR="$(pkg-config --variable=includedir lua$lver)" \
			LUA_LIBDIR="$(pkg-config --variable=libdir lua$lver)" \
			make --tree=./build \
			"$_rockname-scm-1.rockspec"
			rm "./build/lib/luarocks/rocks-$lver/manifest"
	done
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"

	local path; for path in "lib/luarocks/rocks-$lver" "share/lua/$lver"; do
		mkdir -p "$subpkgdir/usr/${path%/*}"
		mv "$builddir/build/$path" "$subpkgdir/usr/$path/"
	done
}

sha512sums="
cab02c540aad905db1fecd7f62545157c8ff9ea82f9ea602bff7b6093e3940a3a316e212a2efe30fa2439435dae6cd4005c2ee41de6b937d3e5f447bc2128a59  luacov-0.15.0.tar.gz
8694e1d5f72da049909d1a868c5b159721c81d20ce5cf9061069732cf6d52e24a9453ad172dec47baf605ed45a8501a7f5131d6bf7609d6b81d1e1eb451e5ce9  reporter_fix.lua.patch
"
